import 'dart:ffi';

import 'package:flutter/material.dart';

class MoveDownHide extends StatefulWidget{
  Widget child;
  double state;

  MoveDownHide({
    required this.child,
    required this.state,
  });

  @override
  _moveDownHide createState(){
    return new _moveDownHide();
  }
}


class _moveDownHide  extends State<MoveDownHide> with SingleTickerProviderStateMixin {

  _moveDownHide();

  late Animation<double> animation;
  late AnimationController controller;


  @override
  void dispose() {

    controller.dispose();
    // TODO: implement dispose
    super.dispose();
  }


  @override
  void initState() {
    super.initState();
    controller = AnimationController(duration: const Duration(milliseconds: 500), vsync: this);
    animation = CurvedAnimation(parent: controller, curve: Curves.easeIn)..addStatusListener((status) {

    });
    //controller.forward();
  }

  Widget build(BuildContext context) {

    if(widget.state == 1){
      (controller as AnimationController).forward();
    }

    if(widget.state == 2){
      (controller as AnimationController).reverse();
    }

    return Container(
      child: _moveDownHideBox(animation: animation,child:widget.child,state:widget.state),
    );
  }
}

class _moveDownHideBox extends AnimatedWidget {
  Widget child;
  double state;

  _moveDownHideBox({super.key, required Animation<double> animation,required this.child,required this.state})
      : super(listenable: animation);

  // Make the Tweens static because they don't change.

  static final _blurRadiusTween = Tween<double>(begin: 20, end:0);


  static final _opacityTween = Tween<double>(begin: 0, end:1);

  @override
  Widget build(BuildContext context) {
    final animation = listenable as Animation<double>;

    return Container(
      padding: EdgeInsets.fromLTRB(0, _blurRadiusTween.evaluate(animation), 0, 0),
              child: Opacity(
                opacity:_opacityTween.evaluate(animation) ,
                child: child,
              ),

    );
  }
}